<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>登录页面</title>
    <meta name="keywords" content="Bootstrap模版,Bootstrap模版下载,Bootstrap教程,Bootstrap中文"/>
    <meta name="description" content="站长素材提供Bootstrap模版,Bootstrap教程,Bootstrap中文翻译等相关Bootstrap插件下载"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <!-- basic styles -->

    <link href="__PUBLIC__/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="__PUBLIC__/css/font-awesome.min.css"/>

    <!--[if IE 7]>
    <link rel="stylesheet" href="__PUBLIC__/css/font-awesome-ie7.min.css"/>
    <![endif]-->

    <link rel="stylesheet" href="__PUBLIC__/css/ace.min.css"/>
    <link rel="stylesheet" href="__PUBLIC__/css/ace-rtl.min.css"/>

    <!--[if lte IE 8]>
    <link rel="stylesheet" href="__PUBLIC__/css/ace-ie.min.css"/>
    <![endif]-->

    <!-- inline styles related to this page -->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

    <!--[if lt IE 9]>
    <script src="__PUBLIC__/js/html5shiv.js"></script>
    <script src="__PUBLIC__/js/respond.min.js"></script>
    <![endif]-->
</head>

<body class="login-layout">
<div class="main-container">
    <div class="main-content">
        <div class="row" style="margin-top: 100px;">
            <div class="col-sm-10 col-sm-offset-1">
                <div class="login-container">
                    <div class="center">
                        <h1>
                            <i class="icon-leaf green"></i>
                            <span class="white">后台登录模板</span>
                        </h1>
                    </div>

                    <div class="space-6"></div>

                    <div class="position-relative">
                        <div id="login-box" class="login-box visible widget-box no-border">
                            <div class="widget-body">
                                <div class="widget-main">
                                    <h4 class="header blue lighter bigger">
                                        <i class="icon-coffee green"></i>
                                        登录
                                    </h4>

                                    <div class="space-6"></div>

                                    <form>
                                        <fieldset>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input id="username" type="text" class="form-control"
                                                                   placeholder="Username"/>
															<i class="icon-user"></i>
														</span>
                                            </label>

                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input id="password" type="password" class="form-control"
                                                                   placeholder="Password"/>
															<i class="icon-lock"></i>
														</span>
                                            </label>

                                            <div class="space"></div>

                                            <div class="clearfix">
                                                <label class="inline">
                                                    <input type="checkbox" class="ace" id="rememberPwd"/>
                                                    <span class="lbl"> 记住密码</span>
                                                </label>

                                                <button type="button" onclick="login()"
                                                        class="width-35 pull-right btn btn-sm btn-primary">
                                                    <i class="icon-key"></i>
                                                    登录
                                                </button>
                                            </div>

                                            <div class="space-4"></div>
                                        </fieldset>
                                    </form>
                                </div><!-- /widget-main -->

                            </div>
                        </div><!-- /.col -->
                    </div><!-- /.row -->
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__PUBLIC__/js/jquery-1.10.2.min.js"></script>
<script src="__PUBLIC__/layer/layer.js"></script>
<script src="__PUBLIC__/js/jquery.cookie.js"></script>
<script>

    function init() {
        if($.cookie('isRememberPwd') == 'true'){
            $("#username").val($.cookie('username'));
            $("#password").val($.cookie('password'));
            $("#rememberPwd").attr('checked','checked');
        }else{
            $("#rememberPwd").removeAttr('checked');
        }
    }

    function login() {
        var username = $("#username").val();
        var password = $("#password").val();
        if(!username || !password){
            layer.msg('用户名、密码不能为空');
        }

        $.post('/index.php/index/user/login',{"username":username,"password":password},function (ret) {
           if(ret.code == 200){
               var isSelected = $("#rememberPwd").is(':checked');
               if(isSelected){
                   $.cookie('isRememberPwd',true,{
                       expires : 60*60*12,
                       path:'/'
                   });
               }else{
                   $.cookie('isRememberPwd',false,{
                       expires : 60*60*12,
                       path:'/'
                   });
               }

               $.cookie('username',username, {
                   expires : 60*60*12,
                   path:'/'
               });
               $.cookie('password',password,{
                   expires : 60*60*12,
                       path:'/'
               });

               layer.msg('登录成功');
               setTimeout(function () {
                    location.href = '/index.php/index/index/index';
               },2000);
           } else{
               layer.msg(ret.msg);
           }
        });
    }

    init();
</script>
</html>
